package com.ziyun.erp.web.api.goodsCraftPrice;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.utility.JsonUtils;
import com.ziyun.erp.modules.goodsCraftPrice.dto.GoodsCraftPriceDto;
import com.ziyun.erp.modules.goodsCraftPrice.entity.GoodsCraftPriceEntity;
import com.ziyun.erp.modules.goodsCraftPrice.service.GoodsCraftPriceService;
import com.ziyun.erp.modules.quoteAttribute.entity.QuoteAttributeEntity;
import com.ziyun.erp.modules.quoteAttribute.service.QuoteAttributeService;
import io.renren.common.utils.R;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 报价工艺价格API
 *
 * @author zh
 * @email 296588519@qq.com
 * @date 2018-09-10 10:43:12
 */
@RestController
@RequestMapping("port/goodsCraftPrice/quoteGoodsCraftPrice")
public class QuoteGoodsCraftPriceAPi {
    @Autowired
    private GoodsCraftPriceService goodsCraftPriceService;

    @Autowired
    private QuoteAttributeService quoteAttributeService;

    /**
     * 获取报价商品工艺
     */
    @RequestMapping("/getQuoteGoodsCraftList")
    public R getQuoteGoodsCraftList(@RequestBody Map paramBodyMap){
        // 商务印刷/ 数码快印
        String attributeOrigin = paramBodyMap.get("attributeOrigin").toString();
        List<Map<String,Object>> goodsCraftList = quoteAttributeService.getQuoteGoodsCraftList(attributeOrigin);
        return R.ok().put("goodsCraftList", goodsCraftList);
    }


    /**
     * 获取印刷报价商品工艺价格
     */
    @RequestMapping("/getYinhuaGosodsCraftPriceList")
    public R getGoodsCraftPriceList(@RequestBody Map paramBodyMap){
        //商户id
        Long sellerId = Long.valueOf(paramBodyMap.get("sellerId").toString());

        Map<String ,Object> yinshuaGoodsCraftPriceData = goodsCraftPriceService.getYinshuaGoodsCraftPriceList(sellerId);

        return R.ok().put("yinshuaGoodsCraftPriceData", yinshuaGoodsCraftPriceData);
    }

    /**
     * 获取印刷商品工艺选项
     */
    @RequestMapping("/getYinshuaGoodsCraftOptionList")
    public R getYinshuaGoodsCraftOptionList(@RequestBody Map paramBodyMap){

        List<GoodsCraftPriceEntity> yinshuaGoodsCraftOptionPriceList = goodsCraftPriceService.getQuoteGoodsCraftOptionPriceList(paramBodyMap);

        return R.ok().put("yinshuaGoodsCraftOptionPriceList", yinshuaGoodsCraftOptionPriceList);
    }


    /**
     * 保存印刷商品工艺价格
     */
    @RequestMapping("/saveYinshua")
    public R saveYinshua(@RequestBody Map paramBodyMap){
        // 获取当前登录人
        String userName = paramBodyMap.get("userName").toString();
        //商户id
        Long sellerId = Long.valueOf(paramBodyMap.get("sellerId").toString());

        List<GoodsCraftPriceEntity> craftPriceList = JsonUtils.string2Collection(paramBodyMap.get("craftPriceList").toString(),List.class, GoodsCraftPriceEntity.class) ;

        goodsCraftPriceService.saveYinshua(craftPriceList, userName, sellerId);
        return R.ok();
    }

    /**
     * 根据工艺配价Ids删除
     */
    @RequestMapping("/deleteByIds")
    public R deleteByIds(@RequestBody Map paramBodyMap){
        List<Integer> ids = JsonUtils.string2Collection(paramBodyMap.get("ids").toString(), List.class, Integer.class);
        goodsCraftPriceService.deleteByIds(ids);
        return R.ok();
    }

    /**
     * 根据工艺删除
     */
    @RequestMapping("/deleteByAttributeId")
    public R deleteByAttributeId(@RequestBody Map paramBodyMap){
        goodsCraftPriceService.deleteQuoteByAttributeId(paramBodyMap);
        return R.ok();
    }


    /*============ 以下为快印商品工艺价格相关信息 ====================*/

    /**
     * 获取快印报价商品工艺价格
     */
    @RequestMapping("/getKuaiyinGosodsCraftPriceList")
    public R getKuaiyinGosodsCraftPriceList(@RequestBody Map paramBodyMap){

        //商户id
        Long sellerId = Long.valueOf(paramBodyMap.get("sellerId").toString());

        Map<String ,Object> kuaiyinGoodsCraftPriceData = goodsCraftPriceService.getKuaiyinGoodsCraftPriceList(sellerId);

        return R.ok().put("kuaiyinGoodsCraftPriceData", kuaiyinGoodsCraftPriceData);
    }


    /**
     * 获取快印商品工艺选项
     */
    @RequestMapping("/getKuaiyinGoodsCraftOptionList")
    public R getKuaiyinGoodsCraftOptionList(@RequestBody Map paramBodyMap){

        List<GoodsCraftPriceEntity> kuaiyinGoodsCraftOptionPriceList = goodsCraftPriceService.getQuoteGoodsCraftOptionPriceList(paramBodyMap);

        return R.ok().put("kuaiyinGoodsCraftOptionPriceList", kuaiyinGoodsCraftOptionPriceList);
    }

    /**
     * 保存快印商品工艺价格
     */
    @RequestMapping("/saveKuaiyin")
    public R saveKuaiyin(@RequestBody Map paramBodyMap){
        // 获取当前登录人
        String userName = paramBodyMap.get("userName").toString();
        //商户id
        Long sellerId = Long.valueOf(paramBodyMap.get("sellerId").toString());

        List<GoodsCraftPriceEntity> craftPriceList = JsonUtils.string2Collection(paramBodyMap.get("craftPriceList").toString(),List.class, GoodsCraftPriceEntity.class) ;

        goodsCraftPriceService.saveKuaiyin(craftPriceList, userName, sellerId);
        return R.ok();
    }


}
